<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top: 50px"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="入库单编号">
                <a-input placeholder="请输入编号" v-model="queryParam.code"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="rowIndex"
          class="j-table-force-nowrap1"
          :scroll="{ x: true }"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: checkval }"
          @change="handleTableChange"
        />
      </div>
    </a-card>
  </j-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, putAction } from '@api/manage'

export default {
  name: 'BussStorageListModal',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  // props: ['category', "modalWidth",],
  props: {
    category: {
      type: String,
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
    supplierId: {
      type: String,
      required: false,
    },
  },
  data() {
    return {
      description: '库存信息管理页面',
      visible: false,
      title: '选择入库单',
      disableMixinCreated: true,
      queryParam: { storageType: this.category },
      bussinessType: '',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '入库日期',
          align: 'center',
          dataIndex: 'warehouseDate',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '编号',
          align: 'center',
          dataIndex: 'code',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        // {
        //   title:'上级单号',
        //   align:"center",
        //   dataIndex: 'superiorCode'
        // },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'supplierName',
        },
        // {
        //   title:'客户',
        //   align:"center",
        //   dataIndex: 'customerName'
        // },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batchNum',
        },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'materialLotNum',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'num',
        },
      ],
      url: {
        list: '/business/bussStorageNotice/storageList',
        packageList: '/business/bussStoragePackage/storageList',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleSubmit() {
      this.getGoodsSelectRows()
      this.searchReset(false)
      this.onClearSelected()
      this.close()
    },
    add() {
      this.showModal()
    },

    showModal() {
      this.dataSource = []
      this.visible = true
      this.loadData()
    },
    getGoodsSelectRows() {
      let selectedRow = null
      if (this.checkval == 'radio') {
        selectedRow = this.selectionRows[0]
      } else {
        selectedRow = this.selectedRowKeys
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      console.log(selectedRow)
      this.$emit('storageOk', selectedRow)
    },
    initDictConfig() {},
    close() {
      this.searchReset(false)
      this.visible = false
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'date', value: 'storageDate', text: '入库日期' })
      fieldList.push({ type: 'string', value: 'code', text: '编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'createBy', text: '制单人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'createTime', text: '制单日期', dictCode: '' })
      fieldList.push({ type: 'string', value: 'supplierId', text: '供应商id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'customerName', text: '客户', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batchNum', text: '批次号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialLotNum', text: '物料批号', dictCode: '' })
      this.superFieldList = fieldList
    },
    loadData(arg) {
      console.log("this.bussinessType")
      console.log(this.bussinessType)

      let url = ''
      if (this.bussinessType === "1") {
        url = this.url.list
      } else if (this.bussinessType === "2") {
        url = this.url.packageList
      }
      console.log(url)
      if (!url) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      params.supplierId = this.supplierId
      this.loading = true
      getAction(url, params)
        .then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      console.log('gouxuan')
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>